<?php
/**
 * Copyright (c) 2006-2008, Julien PORTALIER
 * http://featherphp.googlecode.com/
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

/**
 * WSSE Authentication (as used by the Atom Publishing Protocol).
 * 
 * @param $username String
 * @param $password String
 * @param $headers Array
 * @param $params Array
 * @param $method String
 * @param $url String
 */
function & ActiveResource_Authentication_WSSE($username, $password, array &$headers, array &$params, $method, $url)
{
	# generates the digest
	$created  = Time::to_atom();
	$nonce    = sha1(uniqid(rand(), true));;
	$digest   = base64_encode(sha1($nonce.$created.$password));
	
	# sets headers
	$headers['Authentication'] = 'WSSE profile="UsernameToken"';
	$headers['X-WSSE'] = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
		$username, $digest, $nonce, $created);
}
?>